﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RayTracing
{    
    public class Color
    {
       float r,g,b;                                         // The R,G, and B Values for our Color.

       public Color(float r, float g, float b)              // Creating a color from rgb values.
       {
           this.r = r;
           this.g = g;
           this.b = b;
       }

       public Color(System.Drawing.Color c)                 // Creating a color from a system Color
        {
           this.r = c.R/256.0f;
           this.g = c.G/256.0f;
           this.b = c.B/256.0f;
       }

       public Color(P3 p)                                   // Creating a color from a P3 (just in case).
       {
           this.r = p.x;
           this.g = p.y;
           this.b = p.z;
       }

       public static Color scale(Color c, float scaler)     // Scaling a Color by a value.
       {
           return new Color(c.r * scaler, c.g * scaler, c.b * scaler);
       }

       public static Color add(Color c, Color c2)           // Adding two Colors together.
       {
           return new Color(c.r + c2.r, c.g + c2.g, c.b + c2.b);
       }

       public static Color average(Color c, Color c2, float d)
       {
           if (d == 1.0f)
               return c;
           return new Color((d * c.r + (1 - d) * c2.r), (d * c.g + (1 - d) * c2.g), (d * c.b + (1 - d) * c2.b));
       }

       public static Color mul(Color c, Color c2)           // Multiplies two Colors together. (may need to modify name).
       {
           return new Color(c.r * c2.r, c.g * c2.r, c.b * c2.b);
       }

       public static Color div(Color c, Color c2)           // Divides two Colors. (may need to modify name).
       {
           return new Color(c.r / c2.r, c.g / c2.g, c.b / c2.b);
       }


       public static float intensity(Color c)               // Returns the lightColor of the Color. Finds the maximum value of
       {                                                    // the R,G, and B values.(Intensity)
           return Math.Max(c.r, Math.Max(c.g, c.b));
       }

       public static System.Drawing.Color toRGB(Color c)    // Turns our Color into a C# Color. Making sure that the rgb vals 
       {                                                    // are no bigger than 255 and no less than 0.
           float x = clamp(c.r) * 255;
           float y = clamp(c.g) * 255;
           float z = clamp(c.b) * 255;
           return System.Drawing.Color.FromArgb((int)x,(int)y,(int)z);
       }

        public static float clamp(float val){               // Clamps the value between 0 and one.
            return (float) Math.Min(1,Math.Max(0,val));
        }

        // Static colors so we dont have to say new color every time we want a color.
        // Colors can be defined from System.Draying.Color or from your own creation as long as values are between 0 and 1.

        public static Color RED = new Color(System.Drawing.Color.Red);
        public static Color GREEN = new Color(System.Drawing.Color.Green);
        public static Color BRIGHTGREEN = new Color(0,1,0);
        public static Color BLUE = new Color(System.Drawing.Color.Blue);
        public static Color ORANGE = new Color(System.Drawing.Color.DarkOrange);
        public static Color YELLOW = new Color(System.Drawing.Color.Yellow);
        public static Color PURPLE = new Color(System.Drawing.Color.Purple);
        public static Color BROWN = new Color(System.Drawing.Color.Brown);
        public static Color GRAY = new Color(System.Drawing.Color.Gray);
        public static Color WHITE = new Color(System.Drawing.Color.White);
        public static Color BLACK = new Color(System.Drawing.Color.Black);
        public static Color CYAN = new Color(System.Drawing.Color.Cyan);

    }
}
